﻿<Window x:Class="BulkRenamer.App.WPF.Views.MainWindow" x:Name="this"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:conv="clr-namespace:BulkRenamer.App.WPF.Converters"
        xmlns:extn="clr-namespace:CommonUtilities.Extensions;assembly=CommonUtilities"
        xmlns:toolkit="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ctrl="clr-namespace:BulkRenamer.App.WPF.Controls"
        Title="{Binding AppName}" MinHeight="490" MinWidth="740" MouseDown="this_MouseDown"
        mc:Ignorable="d" d:DesignHeight="490" d:DesignWidth="740" SizeToContent="WidthAndHeight" 
        Background="{StaticResource DefaultWindowBackground}" WindowStartupLocation="CenterScreen" WindowState="Normal">
    <Window.Resources>
        <!--CONVERTERS-->
        <conv:CountConverter x:Key="CountConverter" />
        <conv:FileDetailsConverter x:Key="FileDetailsConverter" />
        <conv:PathValidatorConverter x:Key="PathValidatorConverter" />

        <sys:Int32 x:Key="iDirButtonWidth">50</sys:Int32>
        <sys:Int32 x:Key="iBrowseButtonWidth">80</sys:Int32>

        <!--STYLES-->
    </Window.Resources>

    <Grid Name="MainLayout">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Menu Name="mnuitmHeader" Grid.ColumnSpan="5">
            <MenuItem Header="_Min" />
            <MenuItem Header="Bulk_Renamer" />
        </Menu>

        <Grid Name="grdBody" Grid.Row="1" Margin="5,5,5,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80" />
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Label Name="lblLogPath" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Content="Log Path:" FontWeight="Bold" />
            <ctrl:WatermarkTextBox x:Name="txtLogPath" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" 
                     Foreground="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource PathValidatorConverter}, ConverterParameter=File}"
                     Text="{Binding LogPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource FileDetailsConverter}, ConverterParameter=LogPath}" IsReadOnly="True" />
            <Button Name="btnBrowseLogFile" Grid.Row="1" Grid.Column="5" Width="{Binding Source={StaticResource iBrowseButtonWidth}}" 
                    Content="Browse.." Command="{Binding BrowseLogPathCommand}" />

            <Label Name="lblBasePath" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Base Dir:" FontWeight="Bold" />
            <ctrl:WatermarkTextBox x:Name="txtBasePath" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" 
                     Foreground="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource PathValidatorConverter}, ConverterParameter=Directory}"
                     Text="{Binding SelectedBasePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource FileDetailsConverter}, ConverterParameter=BasePath}" />
            <Button Name="btnBrowseBasePath" Grid.Row="2" Grid.Column="4" Width="{Binding Source={StaticResource iBrowseButtonWidth}}" 
                    Content="Browse.." Command="{Binding BrowseBasePathCommand}" />
            <CheckBox Name="chkAutoLoadFiles" Grid.Row="2" Grid.Column="5" HorizontalAlignment="Left" VerticalAlignment="Center" 
                      Panel.ZIndex="{x:Static sys:Int32.MaxValue}" IsChecked="{Binding IsAutoLoad, Mode=TwoWay}" IsEnabled="{Binding IsLoadEnabled}" />
            <Button Name="btnLoadFiles" Grid.Row="2" Grid.Column="5" Width="{Binding Source={StaticResource iBrowseButtonWidth}}" 
                    Content="Load.." Command="{Binding LoadFilesCommand}" IsEnabled="{Binding IsLoadEnabled}" />

            <StackPanel Name="stkFetchFolders" Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="3" 
                        Margin="0,0,0,20"  HorizontalAlignment="Right" Orientation="Horizontal">
                <Label Name="lblFetchFolders" Content="{Binding SubDirectoryCount, StringFormat='Fetch folders: {0}', FallbackValue='Fetch folders:                '}" />
                <Button Name="btnFetchDirUp" Width="{Binding Source={StaticResource iDirButtonWidth}}" Content="Up" IsEnabled="{Binding IsFetchDirUpEnabled}" 
                        Command="{Binding FetchDirectoryCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Name}" />
                <Button Name="btnFetchDirDown" Width="{Binding Source={StaticResource iDirButtonWidth}}" Content="Down" IsEnabled="{Binding IsFetchDirDownEnabled}" 
                        Command="{Binding FetchDirectoryCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Name}" />
                <Button Name="btnFetchDirPrev" Width="{Binding Source={StaticResource iDirButtonWidth}}" Content="&lt; Prev" IsEnabled="{Binding IsFetchDirPrevEnabled}" 
                        Command="{Binding FetchDirectoryCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Name}" />
                <Button Name="btnFetchDirNext" Width="{Binding Source={StaticResource iDirButtonWidth}}" Content="Next &gt;" IsEnabled="{Binding IsFetchDirNextEnabled}" 
                        Command="{Binding FetchDirectoryCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Name}" />
            </StackPanel>

            <Grid Name="grdFileOps" Grid.Row="3" Grid.ColumnSpan="2" 
                  Margin="0,20,0,2" HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Button Name="btnDelete" Margin="0" HorizontalAlignment="Left" Width="{Binding Source={StaticResource iBrowseButtonWidth}}" 
                        Content="{Binding DeleteButtonText}" Command="{Binding DeleteFilesCommand}" IsEnabled="{Binding IsDeleteEnabled}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseEnter">
                            <i:InvokeCommandAction Command="{Binding UpdateDeleteButtonTextCommand}" CommandParameter="Enter" />
                        </i:EventTrigger>
                        <i:EventTrigger EventName="MouseLeave">
                            <i:InvokeCommandAction Command="{Binding UpdateDeleteButtonTextCommand}" CommandParameter="Leave" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Button>
                <CheckBox Name="chkExtnFilterSelMode" Grid.Column="1" HorizontalAlignment="Right" Content="All" IsChecked="{Binding IsAllFilters}" />

                <Grid Name="grdExtnFilters" Grid.Column="2">
                    <ComboBox Name="cmbExtnFilters" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                              HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" 
                              ItemsSource="{Binding AllFilters}" SelectedValuePath="Value">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <CheckBox Content="{Binding Id}" IsChecked="{Binding Value}">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Checked">
                                            <i:InvokeCommandAction Command="{Binding DataContext.ApplyExtnFilterCommand, RelativeSource={RelativeSource AncestorType=ComboBox}}" CommandParameter="{Binding Id}" />
                                        </i:EventTrigger>
                                        <i:EventTrigger EventName="Unchecked">
                                            <i:InvokeCommandAction Command="{Binding DataContext.ApplyExtnFilterCommand, RelativeSource={RelativeSource AncestorType=ComboBox}}" CommandParameter="{Binding Id}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </CheckBox>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                    <ToggleButton Name="tglExtnFilterSummary" VerticalAlignment="Stretch" Content="{Binding FilterText, Mode=OneWay}" 
                                  BorderBrush="Transparent" BorderThickness="0"
                                  IsChecked="{Binding ElementName=cmbExtnFilters, Path=IsDropDownOpen, Mode=TwoWay}" Grid.Column="2" Margin="0,0,17,0" />
                </Grid>
            </Grid>

            <ListBox Name="lstFileDetails" Grid.Row="4" Grid.RowSpan="3" Grid.ColumnSpan="2" HorizontalAlignment="Stretch"
                     ItemsSource="{Binding AllFilteredFileDetails}" SelectionMode="Extended" SelectedValuePath="NameOrg"
                     SelectedItem="{Binding SelectedFileDetails, Mode=TwoWay}" IsEnabled="{Binding IsNameListEnabled}"
                     ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Auto">
                <!--<ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="IsSelected" Value="{Binding IsNameSelected, Mode=TwoWay}" />
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Red"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>-->
                <!--<i:Interaction.Triggers>
                    <i:EventTrigger EventName="DoubleClick">
                        <i:InvokeCommandAction Command="{Binding OpenFileDetailsCommand}" CommandParameter="{Binding }" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>-->
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Name="stkFileName" Orientation="Horizontal">
                            <Button Name="btnLoadFileDetails" Content="&gt;" Command="{Binding DataContext.OpenFileDetailsCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding }" />
                            <CheckBox Name="chkIsFileSelected" IsChecked="{Binding IsNameSelected, Mode=TwoWay}" Content="{Binding NameOrg}" />
                            <!--<CheckBox Name="chkIsFileSelected" IsChecked="{Binding IsNameSelected, Mode=TwoWay}">
                                <ToggleButton Name="tglFileName" IsChecked="{Binding IsNameSelected, Mode=TwoWay}">
                                    <ToggleButton.Template>
                                        <ControlTemplate TargetType="ToggleButton">
                                            <TextBlock Name="txtbFileName" Text="{Binding NameOrg}" />
                                        </ControlTemplate>
                                    </ToggleButton.Template>
                                </ToggleButton>
                            </CheckBox>-->
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <GridSplitter Grid.Column="2" Grid.RowSpan="7" Width="5" />

            <GroupBox Name="grpOutput" Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="3" MaxWidth="420" 
                      Margin="10,5" Header=".:: Output ::." IsEnabled="{Binding IsOutputEnabled}">
                <Grid Name="grdOutput">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Button Name="btnSuggestNames" Grid.Column="0" HorizontalAlignment="Stretch" Content="Suggest Names (G)" 
                            Command="{Binding SuggestNamesCommand}" CommandParameter="{Binding ElementName=btnSuggestNames}" IsEnabled="{Binding IsSuggestEnabled }" />
                    <Button Name="btnUpdateFiles" Grid.Column="2" HorizontalAlignment="Stretch" Content="Update files (S)" 
                            Command="{Binding UpdateFilesCommand}" IsEnabled="{Binding IsUpdateFilesEnabled}" />

                    <Grid Name="grdTrimLen" Grid.Column="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <CheckBox Name="chkMid" Margin="5,1" Content="M" FontWeight="Bold" 
                                  IsChecked="{Binding IsMidChecked, Mode=TwoWay}" />
                        <UniformGrid Name="ugridTrimLen" Grid.Column="1" Height="23" Columns="2">
                            <toolkit:IntegerUpDown Name="numLTrim" Value="{Binding LTrimLen, Mode=TwoWay}" 
                                                   Minimum="{Binding LTrimMin}" Maximum="{Binding LTrimMax}" />
                            <toolkit:IntegerUpDown Name="numRTrim" Margin="2,1" Value="{Binding RTrimLen, Mode=TwoWay}" 
                                                   Minimum="{Binding RTrimMin}" Maximum="{Binding RTrimMax}" />
                        </UniformGrid>
                    </Grid>

                    <TextBox Name="txtPatten" Grid.Row="1" TextAlignment="Center" 
                             Text="{Binding UpdatePatternText, Converter={StaticResource FileDetailsConverter}, ConverterParameter=Pattern}" 
                             IsEnabled="{Binding txtPattern_Enabled}" IsReadOnly="True" />
                    <TextBox Name="txtAppend" Grid.Row="1" Grid.Column="1" TextAlignment="Center" 
                             Text="{Binding UpdateAppendText, Mode=TwoWay, Converter={StaticResource FileDetailsConverter}, ConverterParameter=Append}" 
                             IsEnabled="{Binding txtAppend_Enabled}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="TextChanged">
                                <i:InvokeCommandAction Command="{Binding SuggestNamesCommand}" CommandParameter="{Binding ElementName=btnSuggestNames}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </TextBox>
                    <TextBox Name="txtReplace" Grid.Row="1" Grid.Column="2" TextAlignment="Center" 
                             Text="{Binding UpdateReplaceText, Mode=TwoWay, Converter={StaticResource FileDetailsConverter}, ConverterParameter=Replace}" 
                             IsEnabled="{Binding txtReplace_Enabled}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="TextChanged">
                                <i:InvokeCommandAction Command="{Binding SuggestNamesCommand}" CommandParameter="{Binding ElementName=btnSuggestNames}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </TextBox>
                </Grid>
            </GroupBox>

            <GroupBox Name="grpEditor" Grid.Row="5" Grid.Column="3" Grid.ColumnSpan="3" MaxWidth="420" 
                      Margin="10,5" Header=".:: Editor ::." IsEnabled="{Binding IsEditorEnabled}">
                <Grid Name="grdEditor" Height="112">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="90" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Label Name="lblNameOrg" HorizontalAlignment="Right" Content="Original" FontWeight="Bold" />
                    <TextBox Name="txtNameOrg" Grid.Column="1" Grid.ColumnSpan="3" 
                             Text="{Binding SelectedFileDetails.NameOrg, Converter={StaticResource FileDetailsConverter}, ConverterParameter=NameOrg}" IsReadOnly="True" />

                    <RadioButton Name="radSuggested" Grid.Row="1" Margin="5" VerticalContentAlignment="Center" HorizontalAlignment="Right" 
                                 Content="Suggested" IsChecked="{Binding SelectedFileDetails.TakeSuggested, Mode=TwoWay}" />
                    <ctrl:WatermarkTextBox x:Name="wtxtNameSugg" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" 
                                           Text="{Binding SelectedFileDetails.NameSuggested, Converter={StaticResource FileDetailsConverter}, ConverterParameter=NameSugg}" IsReadOnly="True" />

                    <RadioButton Name="radCustom" Grid.Row="2" HorizontalAlignment="Right" Content="Custom" />
                    <TextBox x:Name="txtCustom" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" 
                             Text="{Binding SelectedFileDetails.NameCustom, Mode=TwoWay, Converter={StaticResource FileDetailsConverter}, ConverterParameter=NameCust}" />

                    <Label Name="lblExtn" Grid.Row="3" HorizontalAlignment="Right" Content="Extn" FontWeight="Bold" />
                    <TextBox Name="txtExtn" Grid.Row="3" Grid.Column="1" Width="50" 
                             Text="{Binding SelectedFileDetails.FileExtn, Converter={StaticResource FileDetailsConverter}, ConverterParameter=FileExtn}" IsReadOnly="True" />

                    <StackPanel Grid.Row="4" Grid.Column="2" HorizontalAlignment="Right" Orientation="Horizontal">
                        <CheckBox Name="chkAddSeparator" Content="+Ep Separator" IsChecked="{Binding AddSeparator}" FontWeight="Bold" />
                        <CheckBox Name="chkAutoUpdate" IsChecked="{Binding IsAutoUpdate, Mode=TwoWay}" />
                        <Button Name="btnUpdateDetails" Content="Update details" />
                    </StackPanel>
                </Grid>
            </GroupBox>

            <GroupBox Name="grpDataMgmt" Grid.Row="5" Grid.Column="3" Grid.RowSpan="2" Grid.ColumnSpan="3" MaxWidth="420" 
                      Margin="10,5,10,0" VerticalAlignment="Bottom" Header=".:: Bulk ::.">
                <Grid Name="grdDataMgmt">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <StackPanel Name="stkDataMgmt" Orientation="Horizontal">
                        <Button Name="btnImport" Content="Import" />
                        <Button Name="btExnport" Content="Export" IsEnabled="{Binding IsExportEnabled   }"  />
                    </StackPanel>

                    <TextBox Name="txtImportPath" Grid.Row="1" 
                             Foreground="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource PathValidatorConverter}, ConverterParameter=File}"
                             Text="{Binding DataMgmtPath, Mode=TwoWay, Converter={StaticResource FileDetailsConverter}, ConverterParameter=DataMgmt}" />
                    <Button Name="btnBrowseAsynchFile" Grid.Row="1" Grid.Column="1" Content="Browse.." />
                </Grid>
            </GroupBox>
            <Button Content=".: T E S T :." Grid.Column="3" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="10,20,0,0" 
                    Name="button1" Background="Red" Foreground="White" FontWeight="Black" FontStretch="ExtraExpanded" VerticalAlignment="Top" Width="75" Command="{Binding TestCommand}" />
        </Grid>

        <StatusBar Name="stkFooter" Grid.Row="2" Grid.ColumnSpan="5" Background="Transparent">
            <StatusBarItem Name="stitmCounts">
                <UniformGrid Name="ugrdCounts" Width="{Binding ElementName=lstFileDetails, Path=ActualWidth}" Columns="2" VerticalAlignment="Bottom">
                    <StackPanel Name="stkRecCount" Orientation="Horizontal">
                        <Label Name="lblRecCount" Content="Count: " FontWeight="Bold" />
                        <TextBlock Name="txtbRecCount" VerticalAlignment="Center" Background="White" TextAlignment="Center" 
                                   Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"
                                   Text="{Binding RecCount, Converter={StaticResource CountConverter}}" />
                    </StackPanel>
                    <StackPanel Name="stkSelCount" Orientation="Horizontal">
                        <Label Name="lblSelCount" Content="Selected: " FontWeight="Bold" />
                        <TextBlock Name="txtbSelCount" VerticalAlignment="Center" Background="White" TextAlignment="Center" 
                                   Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"
                                   Text="{Binding SelCount, Converter={StaticResource CountConverter}}">
                            <TextBlock.ToolTip>
                                <TextBlock Text="{Binding ElementName=txtbSelCount, Path=Text}" />
                            </TextBlock.ToolTip>
                        </TextBlock>
                    </StackPanel>
                </UniformGrid>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
